<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>使用es6语法Class创建组件</title>
</head>
<body>
<div class="app"></div>
</body>

<script src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>


<script type="text/babel">
    class App extends React.Component {
        constructor(props) {
            super(props);

            this.state = {
                firstName: "kobe",
                lastName: "bryant",
                age: 20
            }
        }

        render() {
            return (
                <div>
                    {/* 运算表达式 */}
                    <h2>{this.state.firstName + " " + this.state.lastName}</h2>
                    {/* 三元运算符 */}
                    <h2>{this.state.age >= 18 ? "成年人": "未成年人"}</h2>
                    {/* 执行一个函数 */}
                    <h2>{this.sayHello("kobe")}</h2>
                </div>
            )
        }

        sayHello(name) {
            return "Hello " + name;
        }
    }

    ReactDOM.render(<App />
        , document.getElementsByClassName('app')[0]);
</script>
</html>